package com.chai.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.chai.dao.TravelItemDao;
import com.chai.pojo.TravelItem;
import com.chai.service.TravelItemService;
import com.chai.vo.PageResult;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service(interfaceClass = TravelItemService.class)
@Transactional
public class TravelItemServiceImpl implements TravelItemService {

    @Autowired
    TravelItemDao travelItemDao;

    @Override
    public void add(TravelItem travelItem) {

        travelItemDao.add(travelItem);
    }

    @Override
    public PageResult findPage(Integer currentPage, Integer pageSize, String queryString) {
        //分页插件
        //（？ ？）几页  每页几条
        PageHelper.startPage(currentPage, pageSize);

        Page<TravelItem> page = travelItemDao.findPage(queryString);

        return new PageResult(page.getTotal(), page.getResult());
    }

    @Override
    public TravelItem get(Integer id) {

        return travelItemDao.get(id);
    }

    @Override
    public void update(TravelItem travelItem) {

        travelItemDao.update(travelItem);
    }

    @Override
    public void delete(Integer id) {

        travelItemDao.delete(id);
    }

    @Override
    public List<TravelItem> findAll() {
        return travelItemDao.findAll();
    }
}
